// 异步方法
const soonsModel = require('../model/soonsModel');
const filmsManageModel = require('../model/filmsManageModel');
// 增
module.exports.insert = async function (soons) {
    // let data= await filmsManageModel.findById(hotShow);
    return await soonsModel.create(soons);
    // return await hotShowModel.create(hotShow);
}
// 查
module.exports.find = async function (page, searchParams) {
    // return await hotMoviesModel.find(searchParams);
    let { current, pageSize } = page;
    // 根据查询条件获取总数
    let total = await soonsModel.countDocuments(searchParams);
    // 根据查询条件获取具体数量的数据
    console.log("total:"+total);
    let data = await soonsModel.find(searchParams)
        .populate({ path: "films" }) // 关联电影
        .limit(pageSize)
        .skip((current - 1) * pageSize);
        console.log("dao:"+data);
    return {
        current, pageSize, total, rows: data,
    }
}

module.exports.findById = async function (id) {
    return await soonsModel.findById(id);
}

// 删
module.exports.delete = async function (id) {
    return await soonsModel.deleteOne({ _id: id });
}
// 改
// module.exports.update = async function (hotShow) {
//     return await hotShowModel.updateOne({ _id: hotShow._id }, hotShow);
// }
// module.exports.findByUsername = async function (name) {
//     return await hotMoviesModel.find({ name });
// }